#if !defined(ximera_threading_messagequeue_hpp)
#define ximera_threading_messagequeue_hpp

// -----------------------------------------------------------

#include <ximera/types.hpp>
#include <boost/thread/mutex.hpp>
#include <queue>

namespace ximera { namespace threading {

    /*! \brief Class that represents a message sent by another thread.
     *  
     *  Each plugin must implement this interface for each type of message 
     *  that it wants to send to the other thread      
     */
    class XIMERA_API IMessage
    {
    public:
        virtual ~IMessage() { }

        /*! \brief This method is called to process the message.
         *
         *  When implementing this method you must put code to call the event or to make some other thing.
         */
        virtual void process() = 0;
    };

    //! \brief Class to handle message queues between threads.
    class XIMERA_API MessageQueue
    {
    public:
        //! \brief Creates an instance of MessageQueue and initializes the internal variables.
        MessageQueue();

        //! \brief Destroys the instance of the class and releases the internal variables.
        ~MessageQueue();

        /*! \brief Adds a message to the message queue.
         *  
         *  \param message The instance of the message to add.
         */
        void addMessage(IMessage* message);

        /*! \brief Processes all the messages in queue.
         *  
         *  Iterates one by one the messages in the queue, calling the IMessage::process method of each message.
         */
        void processMessages();

    private:
        boost::mutex _mutex;
        std::queue<IMessage*> _messages;
        bool _deleting;
    };
}}

// -----------------------------------------------------------

#endif
